package com.molichuxing.services.infrastructure.convertor;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.BeanUtils;

import com.molichuxing.services.infrastructure.bean.ComplaintBean;
import com.molichuxing.services.infrastructure.bean.DrivingLicenseBean;
import com.molichuxing.services.infrastructure.bean.EnterpriseBean;
import com.molichuxing.services.infrastructure.bean.IdentityCardBean;
import com.molichuxing.services.infrastructure.bean.MessageCenterBean;
import com.molichuxing.services.infrastructure.bean.MessageContentBean;
import com.molichuxing.services.infrastructure.bean.UserBean;
import com.molichuxing.services.infrastructure.bean.UserDetailBean;
import com.molichuxing.services.infrastructure.bean.UserPayeeBean;
import com.molichuxing.services.infrastructure.dto.request.create.MessageCenterCreateDto;
import com.molichuxing.services.infrastructure.dto.request.create.MessageContentCreateDto;
import com.molichuxing.services.infrastructure.dto.request.create.UserPayeeCreateDto;
import com.molichuxing.services.infrastructure.dto.request.modify.ComplaintModifyDto;
import com.molichuxing.services.infrastructure.dto.request.modify.DrivingLicenseModifyDto;
import com.molichuxing.services.infrastructure.dto.request.modify.UserPayeeModifyDto;
import com.molichuxing.services.infrastructure.dto.response.ComplaintDto;
import com.molichuxing.services.infrastructure.dto.response.DrivingLicenseDto;
import com.molichuxing.services.infrastructure.dto.response.EnterpriseDto;
import com.molichuxing.services.infrastructure.dto.response.IdentityCardDto;
import com.molichuxing.services.infrastructure.dto.response.MessageCenterDto;
import com.molichuxing.services.infrastructure.dto.response.MessageContentDto;
import com.molichuxing.services.infrastructure.dto.response.UserDetailDto;
import com.molichuxing.services.infrastructure.dto.response.UserDto;
import com.molichuxing.services.infrastructure.dto.response.UserPayeeDto;
import com.molichuxing.services.property.DrivingLicenseStatusEnum;
import com.molichuxing.services.property.DrivingLicenseVerifyStatusEnum;

/**
 * 
 * @author liyg
 * 数据转换类
 * 2019-08-12
 * 
 */
public class Convert {

	/*********************************用户转换开始*************************************************/
	public static List<UserDto> toUserDto(List<UserBean> beanList){
		List<UserDto> dtoList = null;;
		if (beanList != null && beanList.size() > 0) {
			dtoList = new ArrayList<>();
			for (UserBean user : beanList) {
				dtoList.add(toUserDto(user));
			}
		}
		
		return dtoList;
	}
	
	public static UserDto toUserDto(UserBean bean) {
		UserDto beanDto = null;
		if (bean != null) {
			beanDto = new UserDto();
			BeanUtils.copyProperties(bean, beanDto);
		}
		return beanDto;
	}
	
	public static List<IdentityCardDto> toIdentityCardDto(List<IdentityCardBean> beanList){
		List<IdentityCardDto> dtoList = null;;
		if (beanList != null && beanList.size() > 0) {
			dtoList = new ArrayList<>();
			for (IdentityCardBean identityCard : beanList) {
				dtoList.add(toIdentityCardDto(identityCard));
			}
		}
		
		return dtoList;
	}
	
	public static IdentityCardDto toIdentityCardDto(IdentityCardBean bean) {
		IdentityCardDto beanDto = null;
		if (bean != null) {
			beanDto = new IdentityCardDto();
			BeanUtils.copyProperties(bean, beanDto);
		}
		return beanDto;
	}
	
	public static List<UserDetailDto> toUserDetailDto(List<UserDetailBean> beanList){
		List<UserDetailDto> dtoList = null;;
		if (beanList != null && beanList.size() > 0) {
			dtoList = new ArrayList<>();
			for (UserDetailBean userDetail : beanList) {
				dtoList.add(toUserDetailDto(userDetail));
			}
		}
		
		return dtoList;
	}
	
	public static UserDetailDto toUserDetailDto(UserDetailBean bean) {
		UserDetailDto beanDto = null;
		if (bean != null) {
			beanDto = new UserDetailDto();
			BeanUtils.copyProperties(bean, beanDto);
		}
		return beanDto;
	}
   
	/*********************************用户转换结束*************************************************/
	
	
	/*********************************驾驶证转换开始*************************************************/
	
	public static List<DrivingLicenseDto> toDrivingLicenseDto(List<DrivingLicenseBean> beanList){
		List<DrivingLicenseDto> dtoList = null;;
		if (beanList != null && beanList.size() > 0) {
			dtoList = new ArrayList<>();
			for (DrivingLicenseBean drivingLicense : beanList) {
				dtoList.add(toDrivingLicenseDto(drivingLicense));
			}
		}
		
		return dtoList;
	}
	
	public static DrivingLicenseDto toDrivingLicenseDto(DrivingLicenseBean bean) {
		DrivingLicenseDto beanDto = null;
		if (bean != null) {
			beanDto = new DrivingLicenseDto();
			BeanUtils.copyProperties(bean, beanDto);
		}
		return beanDto;
	}
	
	public static DrivingLicenseBean toDrivingLicense(DrivingLicenseModifyDto modifyDto) {
		DrivingLicenseBean bean = new DrivingLicenseBean();
		if (modifyDto != null) {
			bean.setId(modifyDto.getId());
			bean.setVerifyTime(modifyDto.getVerifyTime());
			bean.setVerifyStatus(modifyDto.getVerifyStatus());
			if (modifyDto.getVerifyStatus() == DrivingLicenseVerifyStatusEnum.APPROVE.getValue()) {
				bean.setStatus(DrivingLicenseStatusEnum.VERIFY_PASS.getValue());
			} else {
				bean.setStatus(DrivingLicenseStatusEnum.VERIFY_FAILURE.getValue());
			}
			bean.setRejectReason(modifyDto.getRejectReason());
			bean.setAccountId(modifyDto.getOperateId());
			bean.setAccountAccount(modifyDto.getOperateName());
		}
		return bean;
	}
	
	/*********************************驾驶证转换结束*************************************************/
	
    /*********************************投诉转换开始*************************************************/
	
	public static List<ComplaintDto> toComplaintDto(List<ComplaintBean> beanList){
		List<ComplaintDto> dtoList = null;;
		if (beanList != null && beanList.size() > 0) {
			dtoList = new ArrayList<>();
			for (ComplaintBean complaint : beanList) {
				dtoList.add(toComplaintDto(complaint));
			}
		}
		
		return dtoList;
	}
	
	public static ComplaintDto toComplaintDto(ComplaintBean bean) {
		ComplaintDto beanDto = null;
		if (bean != null) {
			beanDto = new ComplaintDto();
			BeanUtils.copyProperties(bean, beanDto);
		}
		return beanDto;
	}
	
	public static ComplaintBean toComplaint(ComplaintModifyDto modifyDto) {
		ComplaintBean bean = new ComplaintBean();
		if (modifyDto != null) {
			bean.setId(modifyDto.getId());
			bean.setStatus(modifyDto.getStatus());
			bean.setRemark(modifyDto.getRemark());
			bean.setAccountId(modifyDto.getOperateId());
			bean.setAccountAccount(modifyDto.getOperateName());
			bean.setOperationTime(modifyDto.getOperateDate());
		}
		return bean;
	}



	/*********************************投诉转换结束*************************************************/


	public static MessageCenterBean toMessageCenterBean(MessageCenterCreateDto dto) {
		MessageCenterBean bean = null;
		if(null != dto){
			bean = new MessageCenterBean();
			BeanUtils.copyProperties(dto, bean);
		}
		return bean;
	}

	public static List<MessageContentBean> toMessageContentBean(List<MessageContentCreateDto> dtoList) {
		List<MessageContentBean> beanList = null;
		if (dtoList != null && dtoList.size() > 0) {
			beanList = new ArrayList<>();
			for (MessageContentCreateDto messageContentCreateDto : dtoList) {
				beanList.add(toMessageContentBean(messageContentCreateDto));
			}
		}

		return beanList;
	}

	private static MessageContentBean toMessageContentBean(MessageContentCreateDto dto) {
		MessageContentBean bean = null;
		if(null != dto){
			bean = new MessageContentBean();
			BeanUtils.copyProperties(dto, bean);
		}
		return bean;
	}

	public static List<MessageCenterDto> toMessageCenterDto(List<MessageCenterBean> beanList) {
		List<MessageCenterDto> dtoList = null;
		if (beanList != null && beanList.size() > 0) {
			dtoList = new ArrayList<>();
			for (MessageCenterBean messageCenterBean : beanList) {
				dtoList.add(toMessageCenterDto(messageCenterBean));
			}
		}

		return dtoList;
	}

	private static MessageCenterDto toMessageCenterDto(MessageCenterBean bean) {
		MessageCenterDto dto = null;
		if(null != bean){
			dto = new MessageCenterDto();
			BeanUtils.copyProperties(bean, dto);
		}
		return dto;
	}

	public static List<MessageContentDto> toMessageContentDto(List<MessageContentBean> beanList) {
		List<MessageContentDto> dtoList = null;
		if (beanList != null && beanList.size() > 0) {
			dtoList = new ArrayList<>();
			for (MessageContentBean messageContentBean : beanList) {
				dtoList.add(toMessageContentDto(messageContentBean));
			}
		}

		return dtoList;
	}

	private static MessageContentDto toMessageContentDto(MessageContentBean bean) {
		MessageContentDto dto = null;
		if(null != bean){
			dto = new MessageContentDto();
			BeanUtils.copyProperties(bean, dto);
		}
		return dto;
	}

	public static UserPayeeDto toUserPayeeDto(UserPayeeBean bean) {
		UserPayeeDto dto = null;
		if (null != bean) {
			dto = new UserPayeeDto();
			BeanUtils.copyProperties(bean, dto);
		}
		return dto;
	}

	public static UserPayeeBean toUserPayeeBean(UserPayeeCreateDto createDto) {
		UserPayeeBean bean = null;
		if (null != createDto) {
			bean = new UserPayeeBean();
			BeanUtils.copyProperties(createDto, bean);
		}
		return bean;
	}

	public static UserPayeeBean toUserPayeeBean(UserPayeeModifyDto modifyDto) {
		UserPayeeBean bean = null;
		if (null != modifyDto) {
			bean = new UserPayeeBean();
			BeanUtils.copyProperties(modifyDto, bean);
		}
		return bean;
	}
	
	public static List<EnterpriseDto> toEnterpriseDto(List<EnterpriseBean> beanList){
		List<EnterpriseDto> dtoList = null;;
		if (beanList != null && beanList.size() > 0) {
			dtoList = new ArrayList<>();
			for (EnterpriseBean bean : beanList) {
				dtoList.add(toEnterpriseDto(bean));
			}
		}
		
		return dtoList;
	}
	
	public static EnterpriseDto toEnterpriseDto(EnterpriseBean bean) {
		EnterpriseDto beanDto = null;
		if (bean != null) {
			beanDto = new EnterpriseDto();
			BeanUtils.copyProperties(bean, beanDto);
		}
		return beanDto;
	}
}
